from PyQt4.QtGui import QWidget,QTableWidget,QVBoxLayout,QMainWindow,QMenu,QComboBox
from KReport import KStocksItemModel, KStocksTableView,KReportWidget
from KReport.ui_KStockListBrowseWidget import Ui_KStockListBrowseWidget
from PyQt4 import QtCore
from PyQt4.QtCore import QString,Qt,QStringList
from KDataBase.KQueryDB import KQueryDB
from KReport import KStocksItemModel, KStocksTableView
class KStockListBrowseWidget(QWidget):
	
	SymbolChanged=QtCore.pyqtSignal(str) # triggered by smart look up pass from parent to child
	ReportSelctionChanged=QtCore.pyqtSignal(str) # triggered by view selection pass from child to parent
	

	def __init__(self, parent,reportmodel=KStocksItemModel.KStocksItemModel()):
		super(KStockListBrowseWidget, self).__init__(parent)	
		self.ui =  Ui_KStockListBrowseWidget()
		self.ui.setupUi(self) 

		self.mLayout=QVBoxLayout(self.ui.FrmTable)
		self.mLayout.setContentsMargins(0,0,0,0) # set blank space between outside of layout and its parent widget		
		self.mLayout.setSpacing(0)
		


			
		self.repotwgt=KReportWidget.KReportWidget(self,reportmodel)
		self.mLayout.addWidget(self.repotwgt)
		self.SymbolChanged.connect(self.repotwgt.OnSymbolChanged) # pass symbol change information to report widget
		self.repotwgt.ReportSelctionChanged.connect(self.ReportSelctionChanged) # pass up to parent

		# forward methods to reportwgt
		for m in [ 'UpdateSymbolList', 'UpdateDynamicColumns','GetCurrentSymbolList']: 
			setattr(self, m, getattr(self.repotwgt, m))
			
			
		self.ui.selectwgt.OnDataSetChanged.connect(self.UpdateSymbolList)

		self.UpdateSymbolList(self.ui.selectwgt.GetSymbolListByComboIndex(0)) # set report to be first one by default


